package org.cainiao.basic.collection.listqueue;

import java.util.concurrent.SynchronousQueue;

public class SynchronousQueueTest { // ����Ϊ0

    public static void main(String[] args) throws InterruptedException {
        SynchronousQueue<String> strings = new SynchronousQueue<>();

        new Thread(() -> {
            try {
                Thread.sleep(1000);
                System.out.println(strings.take());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(() -> {
            try {
                Thread.sleep(1000);
                System.out.println(strings.take());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(() -> {
            try {
                strings.put("aaa");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(() -> {
            try {
                strings.put("bbb");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        // strings.put("aaa"); // �����ȴ�����������
        // strings.put("bbb");
        // strings.add("aaa");
        System.out.println(strings.size());
    }

}
